/**
 * 日志中间件
 */
const Log = require('../model/log');

module.exports = {
    /**
     * 获取日志列表
     */
    getPageLog:(req,res,next) =>{
        let size = req.page.size;
        let start = (req.page.p -1)*size;
        Log.getPageLog(start,size).then(results =>{
            req.logs = results;
            next();
        }).catch(err=>{
            next(err);
        });
    },
    /**
     * 获取日志总条目数
     */
    getCount:(req,res,next) =>{
        Log.getCount().then(results =>{
            req.count = results;
            next();
        }).catch(err=>{
            next(err);
        });
    },
    /**
     * 添加日志
     */
    add:(req,res,next) =>{
        Log.add(req.log).then(results =>{
            req.affectedRows = results;
            next();
        }).catch(err=>{
            next(err);
        });
    },
}
